package com.ctl.starter.all;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.StringUtils;

import java.util.Set;
import java.util.TreeSet;

@Slf4j
public class CustomResourceLoader implements ResourceLoader {
  static  Set<String> path=new TreeSet<>();
    private final ResourceLoader delegate;

    public CustomResourceLoader(ResourceLoader delegate) {
        this.delegate = delegate;
    }

    @Override
    public Resource getResource(String location) {
        if (shouldFilter(location)) {
            return null;
        }
        return delegate.getResource(location);
    }

    @Override
    public ClassLoader getClassLoader() {
        return delegate.getClassLoader();
    }

    private boolean shouldFilter(String location) {
        path.add(location);
//        log.info("location={}",location);
//        System.out.println("CustomResourceLoader.location="+location);
        // Implement your filtering logic, e.g., exclude certain file types
        return !StringUtils.hasText(location) || location.endsWith(".exclude");
    }
}
